import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  }

  return { count, doubleCount, increment }
})
export const useLoadingStore = defineStore('loading', () => {
	const loading = ref(0)
	const openLoading = () => { loading.value++ }
	const closeLoading = () => { loading.value-- }
	const getLoading = () => loading.value
	return { loading, openLoading, closeLoading,  getLoading }
})

export const useTokenStore = defineStore('token', () => {
	const token = ref('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzM0LCJwaG9uZSI6IjEzODAwMTM4MDAxIiwiZW1haWwiOiJ6aGFuZ3dlaUBob3NwaXRhbC5jb20iLCJkYXRlIjoxNzU1MjIwNzk5fQ.Bt1j0gn2INCmkGh1N33XKz1Y2NRvMJZ8BdoyCOTO7Bc')
	const setToken = value => { token.value = value }
	const getToken = () => token.value
	return { token, setToken, getToken }
}, {
	persist: {
		storage: sessionStorage
	}
})
export const useRegisterStore = defineStore('register', () => {
	const register = ref(null)
	const setRegister = value => { register.value = value }
	const getRegister = () => register.value
	return { register, setRegister, getRegister }
}, {
	persist: {
		storage: sessionStorage
	}
})